package gui.components.map.engine;

import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JPanel;

public class EngineCounter implements Runnable{
	
	private JPanel _targetpanel;
	
	Timer _timer;
	private int _duration = 25;
	private boolean _timer_active = false;

	
	public EngineCounter(JPanel _jp)
	{
		_targetpanel = _jp;
	}

	public EngineCounter(JPanel _jp, int _timer_duration)
	{
		_targetpanel = _jp;
		_duration = _timer_duration;
	}
	
	public void run()
	{
		start();
	}

	public void suspend()
	{
		Stop();
	}
	
	public void start()
	{
		_timer = new Timer();	
		_timer.scheduleAtFixedRate(new TimerTask() {public void run() {
			_targetpanel.repaint();	
		}}, 0,_duration);
	}
	
	public void Stop()
	{
		_timer.cancel();
	}
	
	public boolean GetCounterActive()
	{
		return _timer_active;
	}
}

